/*
* Copyright (c) 2018. 玺得（深圳）科技有限公司.保留所有权利. http://www.pi-top.com/ 玺得（深圳）科技有限公司保留所有代码著作权.如有任何疑问请访问官方网站与我们联系. 代码只针对特定需求定制编码，不得在未经允许或授权的情况下对外传播扩散.恶意传播者，法律后果自行承担. 本代码仅用于jv-rover系统.
*/
package com.pitop.device.ctrl;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.annotation.Resource;
import java.util.List;
import java.util.HashMap;

import com.pitop.core.entity.BeanRet;
import com.pitop.core.entity.Page;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.device.entity.DevicePool;
import com.pitop.device.service.DevicePoolSV;

/**
* 设备池 控制器
*
* @author lixin
*/
@RestController
@RequestMapping("/devicePool")
@Slf4j
@Api(value = "设备池控制器", description = "设备池控制器")
public class DevicePoolCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private DevicePoolSV devicePoolSV;

    /**
    * 查询DevicePool一个详情信息
    * @param id 
    * @param code 设备编码
    * @param codeName 设备编号
    * @return BeanRet
    */
    @ApiOperation(value = "查询DevicePool一个详情信息", notes = "查询DevicePool一个详情信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "",dataType = "java.lang.Long", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "设备编码",dataType = "java.lang.String", paramType = "query"),
        @ApiImplicitParam(name = "codeName", value = "设备编号",dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public DevicePool load(java.lang.Long id,java.lang.String code,java.lang.String codeName) {
        if(id==null){
        return null;
        }
        if(code==null){
        return null;
        }
        if(codeName==null){
        return null;
        }
        DevicePool devicePool = devicePoolSV.load(id,code,codeName);
        log.info(JSON.toJSONString(devicePool));
        return devicePool;
    }


    /**
    * 根据条件id查询DevicePool一个详情信息
    *
    * @param id 
    * @return BeanRet
    */
    @ApiOperation(value = "查询DevicePool一个详情信息", notes = "查询DevicePool一个详情信息")
    @ApiImplicitParams({
       @ApiImplicitParam(name = "id", value = "",dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public DevicePool loadById(@PathVariable java.lang.Long id) {
        if(id==null){
           return null;
        }
        DevicePool devicePool = devicePoolSV.loadById(id);
        log.info(JSON.toJSONString(devicePool));
        return devicePool;
    }
    /**
    * 根据条件code查询DevicePool一个详情信息
    *
    * @param code 设备编码
    * @return BeanRet
    */
    @ApiOperation(value = "查询DevicePool一个详情信息", notes = "查询DevicePool一个详情信息")
    @ApiImplicitParams({
       @ApiImplicitParam(name = "code", value = "设备编码",dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/code/{code}")
    @ResponseBody
    public DevicePool loadByCode(@PathVariable java.lang.String code) {
        if(code==null){
           return null;
        }
        DevicePool devicePool = devicePoolSV.loadByCode(code);
        log.info(JSON.toJSONString(devicePool));
        return devicePool;
    }
    /**
    * 根据条件codeName查询DevicePool一个详情信息
    *
    * @param codeName 设备编号
    * @return BeanRet
    */
    @ApiOperation(value = "查询DevicePool一个详情信息", notes = "查询DevicePool一个详情信息")
    @ApiImplicitParams({
       @ApiImplicitParam(name = "codeName", value = "设备编号",dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/codeName/{codeName}")
    @ResponseBody
    public DevicePool loadByCodeName(@PathVariable java.lang.String codeName) {
        if(codeName==null){
           return null;
        }
        DevicePool devicePool = devicePoolSV.loadByCodeName(codeName);
        log.info(JSON.toJSONString(devicePool));
        return devicePool;
    }


    /**
    * 查询DevicePool信息集合
    *
    * @return 分页对象
    */
    @ApiOperation(value = "查询DevicePool信息集合", notes = "查询DevicePool信息集合")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
    @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
        @ApiImplicitParam(name = "createTimeBegin", value = "创建时间", paramType = "query"),
        @ApiImplicitParam(name = "createTimeEnd", value = "创建时间", paramType = "query"),
        @ApiImplicitParam(name = "updateTimeBegin", value = "更新时间", paramType = "query"),
        @ApiImplicitParam(name = "updateTimeEnd", value = "更新时间", paramType = "query"),
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public List<DevicePool> list(@RequestBody @ApiIgnore DevicePool devicePool,Integer curPage,Integer pageSize) {
        Page<DevicePool> page=new Page<DevicePool>(pageSize,curPage);
        List<DevicePool> devicePools = devicePoolSV.list(devicePool,page.genRowStart(),page.getPageSize());
        int total = devicePoolSV.count(devicePool);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return devicePools;
    }


    /**
    * 查询DevicePool信息集合
    *
    * @return 分页对象
    */
    @ApiOperation(value = "查询DevicePool信息集合", notes = "查询DevicePool信息集合")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
    @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
    @ApiImplicitParam(name = "code", value = "设备编码", paramType = "query"),
    @ApiImplicitParam(name = "codeName", value = "设备编号", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public List<DevicePool> listByPk(java.lang.Long id,java.lang.String code,java.lang.String codeName,Integer curPage,Integer pageSize) {
        Page<DevicePool> page=new Page<DevicePool>(pageSize,curPage);
        List<DevicePool> devicePools = devicePoolSV.list(id,code,codeName, page.genRowStart(),page.getPageSize());
        int total = devicePoolSV.count(id,code,codeName);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return devicePools;
    }

    /**
    * 统计DevicePool信息数量根据主键
    *
    * @return 总条数
    */
    @ApiOperation(value = " 统计DevicePool信息数量根据主键", notes = " 统计DevicePool信息数量根据主键")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
    @ApiImplicitParam(name = "code", value = "设备编码", paramType = "query"),
    @ApiImplicitParam(name = "codeName", value = "设备编号", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(java.lang.Long id,java.lang.String code,java.lang.String codeName) {
        return devicePoolSV.count(id,code,codeName);
    }

    /**
    * 统计DevicePool信息数量
    *
    * @return 总条数
    */
    @ApiOperation(value = "统计DevicePool信息数量", notes = "统计DevicePool信息数量")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
    @ApiImplicitParam(name = "code", value = "设备编码", paramType = "query"),
    @ApiImplicitParam(name = "codeName", value = "设备编号", paramType = "query"),
    @ApiImplicitParam(name = "barcode", value = "条码纸质上显示 来自pp 系统", paramType = "query"),
    @ApiImplicitParam(name = "serialNumber", value = "序列号,设备内部的唯一识别码", paramType = "query"),
    @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query"),
    @ApiImplicitParam(name = "updateTime", value = "更新时间", paramType = "query"),
    @ApiImplicitParam(name = "state", value = "状态[正常 Normal,维修 Repair]", paramType = "query"),
    @ApiImplicitParam(name = "summary", value = "备注最多128个英文字符或64个汉字", paramType = "query")
    })
    @PostMapping(value = "/count")
    @ResponseBody
    public Integer count(@RequestBody DevicePool devicePool) {
        if(devicePool==null){
            return devicePoolSV.count(new HashMap());
        }else{
            return devicePoolSV.count(devicePool);
        }
    }



    /**
    * 创建DevicePool
    *
    * @return BeanRet
    */
    @ApiOperation(value = "创建DevicePool", notes = "创建DevicePool")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "barcode", value = "条码纸质上显示 来自pp 系统", paramType = "query"),
    @ApiImplicitParam(name = "serialNumber", value = "序列号,设备内部的唯一识别码", paramType = "query"),
    @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query"),
    @ApiImplicitParam(name = "updateTime", value = "更新时间", paramType = "query"),
    @ApiImplicitParam(name = "state", value = "状态[正常 Normal,维修 Repair]", paramType = "query"),
    @ApiImplicitParam(name = "summary", value = "备注最多128个英文字符或64个汉字", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public DevicePool build(@RequestBody @ApiIgnore DevicePool devicePool) {
        devicePoolSV.save(devicePool);
        return devicePool;
    }


    /**
    * 修改DevicePool
    *
    * @return BeanRet
    */
    @ApiOperation(value = "修改DevicePool", notes = "修改DevicePool")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "设备编码", paramType = "query"),
        @ApiImplicitParam(name = "codeName", value = "设备编号", paramType = "query"),
        @ApiImplicitParam(name = "barcode", value = "条码纸质上显示 来自pp 系统", paramType = "query"),
        @ApiImplicitParam(name = "serialNumber", value = "序列号,设备内部的唯一识别码", paramType = "query"),
        @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query"),
        @ApiImplicitParam(name = "updateTime", value = "更新时间", paramType = "query"),
        @ApiImplicitParam(name = "state", value = "状态[正常 Normal,维修 Repair]", paramType = "query"),
        @ApiImplicitParam(name = "summary", value = "备注最多128个英文字符或64个汉字", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public DevicePool modify(@ApiIgnore DevicePool devicePool) {
        devicePoolSV.modify(devicePool);
        return devicePool;
    }

    /**
    * 删除DevicePool
    *
    * @return BeanRet
    */
    @ApiOperation(value = "删除DevicePool", notes = "删除DevicePool")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "设备编码", paramType = "query"),
        @ApiImplicitParam(name = "codeName", value = "设备编号", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id,java.lang.String code,java.lang.String codeName) {
        devicePoolSV.delete(id,code,codeName);
        return BeanRet.create(true, "删除DevicePool成功");
    }

}
